package com.keeping.aiimagery.entity;

import cc.vihackerframework.core.entity.ViHackerEntity;
import com.baomidou.mybatisplus.annotation.*;
import com.keeping.aiimagery.entity.enums.MsgType;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;

/**
 * Created By Ranger on 2023/4/4.
 */
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@TableName("t_chat_record")
public class ChatRecord extends ViHackerEntity {
    
    @TableId(type = IdType.ID_WORKER)
    private Long id;
    
    private MsgType msgType;
    
    private Long roomId;
    
    private String message;


    @TableField(value = "CREATED_BY")
    private Long createdBy;

    /**
     * 创建时间
     */
    @TableField(value = "CREATED_TIME", fill = FieldFill.INSERT)
    private LocalDateTime createdTime;

    /**
     * 修改者
     */
    @TableField(value = "MODIFY_BY")
    private Long modifyBy;

    /**
     * 修改时间
     */
    @TableField(value = "MODIFY_TIME", fill = FieldFill.INSERT_UPDATE)
    private LocalDateTime modifyTime;

    /**
     * 版本信息
     */
    @Version
    @TableField(value = "VERSION")
    private Long version;

    /**
     * 数据逻辑删除标识字段
     */
    @TableLogic
    @TableField(fill = FieldFill.INSERT)
    private Integer deleted;

    public void created(Long userId){
        this.createdBy = userId;
        this.createdTime = LocalDateTime.now();
        this.modifyBy = userId;
        this.modifyTime = LocalDateTime.now();
        this.deleted = 0;
        this.version = 0L;
    }
}
